package com.codenjoy.calculator.base;

import java.util.HashMap;

/**
 * Created by kate on 31.01.2015.
 */
public class RomanBase implements Base {
    public static final String ROMAN_BASE_SIGN = "R";
    public static final String ROMAN_BASE_ONE ="I";
    public static final HashMap<String,Integer> ROMAN_BASE_SYMBOLS= new HashMap<String,Integer>();
    static{
        ROMAN_BASE_SYMBOLS.put("V",new Integer(5));
        ROMAN_BASE_SYMBOLS.put("X",new Integer(10));
    }

    @Override
    public long formatFromBaseToDecimal(String numberInBaseFormat) {
        int index = 0;
        long sum = 0;
        int numberLength = numberInBaseFormat.length();
        while (index < numberLength){
            int oneCount = 0;
            while (index < numberLength && ROMAN_BASE_ONE.equals(getNumberSymbol(numberInBaseFormat, index))){
                index++;
                oneCount++;
            }
            if (index < numberLength){
                String nextSymb = getNumberSymbol(numberInBaseFormat,index);
                sum += (ROMAN_BASE_SYMBOLS.get(nextSymb) - oneCount);
                index++;

            }else{
                sum += oneCount;
            }
        }

        return sum;
    }

    private String getNumberSymbol(String numberInBaseFormat, int index) {
        return String.valueOf(numberInBaseFormat.charAt(index));
    }

    @Override
    public String formatFromDecimalToBase(long num) {
        return null;
    }

    @Override
    public void validateSymbol(char symbol) {

    }
}
